/**
 * Created by Administrator on 2017/3/21.
 */
import React, { Component, Fragment } from 'react';
import { Form, Button, Badge, Select, Radio, Descriptions, Input, Modal } from 'antd';
import { connect } from 'dva';
import moment from 'moment';
import config from '@/config/config';

const { TextArea } = Input;
import request from '@/utils/request';
import PersonalLeave from './../PersonalLeave/LeaveDetail';
const { confirm } = Modal;
import { download, leaveStatue,leaveStatueImg,printLeave } from '@/utils/utils';

const ButtonGroup = Button.Group;

class AddPoliciesForm extends Component {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
  }


  render() {
    const { getFieldDecorator } = this.props.form;
    const editRecord = this.props.editRecord;
    let statusColor1=''
    let statusColor2=''
    if(editRecord.status===3||editRecord.status===5){
      statusColor1='#c60600'
    }else if(editRecord.status===4||editRecord.status===6){
      statusColor1='#1e9680'
    }
    if(editRecord.status===5){
      statusColor2='#c60600'
    }else if(editRecord.status===6){
      statusColor2='#1e9680'
    }
    return (
      <div>
        <PersonalLeave editRecord={this.props.editRecord}/>
        {
          (this.props.editRecord.status === 2 &&
            this.props.editRecord.reviewers.map((item,index)=>{
              return item.name
            }).indexOf(sessionStorage.getItem('username'))>=0)&&

          <Fragment>
            <Descriptions className={'blue-descriptions'} style={{marginTop:'10px'}} title={<div style={{ textAlign: 'center' }}>请假审批</div>} bordered>

              <Descriptions.Item label="审批备注" span={3}>
                {getFieldDecorator('review_remark', {
                  initialValue: this.props.editRecord ? this.props.editRecord.review_remark : '',
                })(
                  <TextArea rows={2}/>,
                )}

              </Descriptions.Item>
              <Descriptions.Item label="审批操作" span={3}>
                {getFieldDecorator('status', {
                  initialValue: 4,
                })(
                  <Radio.Group>
                    <Radio value={4}>通过审批</Radio>
                    <Radio value={3}>不通过审批</Radio>
                  </Radio.Group>,
                )}
                <Button type={'primary'} size={'small'} onClick={() => {
                  const that = this;
                  const formValues = this.props.form.getFieldsValue();
                  confirm({
                    title: `确定要${formValues.status === 4 ? '通过' : '不通过'}审批吗?`,
                    content: '请谨慎操作',
                    okText: '确定',
                    cancelText: '取消',
                    centered: true,
                    maskClosable: true,
                    onOk() {
                      request(`/leave_lists/${editRecord.id}/review`, {
                        method: 'PUT',
                        params: {
                          ...formValues,
                        },
                      }).then((response) => {
                        if (response.status === 200) {
                          that.props.save();
                        }
                      });
                    },
                    onCancel() {
                      console.log('Cancel');
                    },
                  });
                }}>确定</Button>
              </Descriptions.Item>
            </Descriptions>
          </Fragment>
        }
      </div>
    );
  }
}

const AddPoliciesFormWrap = Form.create()(AddPoliciesForm);
export default connect()(AddPoliciesFormWrap);


